package admin

import (
	"encoding/json"
	"net/http"

	"github.com/gin-gonic/gin"

	"ginBasic/app/common/business"
)

type ConfigController struct {
	BaseController
}

func (con ConfigController) Index(c *gin.Context) {
	configList, _ := business.Config.GetList()
	c.HTML(http.StatusOK, "admin/config/index.html", gin.H{
		"config": configList,
		"status": configList["cache_status"],
	})
}

func (con ConfigController) Update(c *gin.Context) {
	var reqObj map[string]interface{}
	data, _ := c.GetRawData()
	json.Unmarshal(data, &reqObj)
	err := business.Config.Update(reqObj)
	if err != nil {
		con.ShowRes(-1, err.Error(), c)
		return
	} else {
		con.ShowRes(0, "操作成功", c)
		return
	}
}
